home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 35 / PC Gamer IT CD 35 2-2.iso / STARDEMO / Starsiege_ATR2.exe / Starsiege / Missions.vol / SWARM_Mai_Lay_Dan.cs < prev    next >
Text File  |  1998-07-30  |  14KB  |  588 lines

  1. //
  2. // tagStdlib.cs
  3. //
  4.  
  5.  
  6. $snuffValue           = 0;
  7. $chokeValue            = 0;
  8. $sackValue            = 0;
  9. $winScore            = 50;
  10. $tagWon                = 0;
  11. $healTriggerReady    = true;
  12. $ammoTriggerReady    = true;
  13.  
  14.  
  15. //----------------------------------------------
  16.  
  17.  
  18.  
  19. function setDefaultMissionOptions()
  20. {
  21.    $server::AllowTeamRed = true;
  22.    $server::AllowTeamBlue = false;
  23.    $server::AllowTeamYellow = true;
  24.    $server::AllowTeamPurple = false;
  25.  
  26.    $server::TeamPlay = true;
  27.    $server::AllowDeathmatch = false;
  28.    $server::AllowTeamPlay = true;    
  29. }
  30.  
  31. function onMissionStart(%playerNum)
  32. {
  33.     setKillValues();
  34.     displayKillValues();
  35.  
  36.     //reinitialize scores of players who were in previous game
  37.     
  38.     %count = playerManager::getPlayerCount();
  39.     for(%i = 0; %i < %count; %i = %i + 1)
  40.     {
  41.         %curPlayerNum = playerManager::getPlayerNum(%i);
  42.         initStats(%curPlayerNum);
  43.     }
  44.  
  45.     //Make first person to enter sim IT
  46.     
  47.     dataStore(0, strcat(%playerNum, "isIt"), "Yes");
  48.     wallDim(strcat(getName(%playerNum), " is now IT!"));
  49.     boundryCheck();
  50.     
  51. }        
  52.         
  53. //-------------------------------------------------------------
  54. function player::onAdd(%playerNum)
  55. {
  56.    setKillValues();
  57.    displayKillValues();
  58.    initStats(%playerNum);
  59.  
  60.    chat(%playerNum,0, strcat("Welcome to Starsiege SWARM, ", getName(%playerNum), ". Here are the rules: "));
  61.    chat(%playerNum,0, strcat("- You get " , $sackValue, " point(s) for SACKING 'IT'."));
  62.    chat(%playerNum,0, strcat("- You get ", $snuffValue, " points for SNUFFING someone while you are 'IT'."));
  63.    chat(%playerNum,0, strcat("- You CHOKE if 'IT' kills you and you lose ", $chokeValue, " point(s)."));
  64.    chat(%playerNum,0, "- You become 'IT' by sacking 'IT'.");
  65.    chat(%playerNum,0, strcat("- The first player to reach ", $winScore, " points wins the game."));
  66.    
  67. }
  68.  
  69. //-------------------------------------------------------------
  70. function player::onRemove(%playerNum)
  71. {
  72.       setKillValues();
  73.     displayKillValues();
  74.       
  75.       
  76.       if(%playerNum == getItNum())
  77.        {
  78.          %newItNum = getHighScorePlayerNum(%playerNum);
  79.  
  80.            if(%newItNum != "" && %newItNum != 0)
  81.         {
  82.               dataStore(0, strcat(%newItNum, "isIt"), "Yes" );
  83.               wall(strcat(getName(%newItNum), " is now IT!"));
  84.             
  85.             %vehicleId = playerManager::playerNumToVehicleId(%newItNum);
  86.             setTeam(%vehicleId, RED);
  87.             setVehicleSpecialIdentity(%vehicleId, true, RED);
  88.  
  89.             resetAmmoTrigger(%newItNum);
  90.             resetHealTrigger(%newItNum);
  91.            }
  92.     }
  93.     
  94.     cleanUp(%playerNum);
  95.     
  96.     
  97. }
  98.  
  99. //-------------------------------------------------------------
  100. function vehicle::onAdd(%vehicleId)
  101. {
  102.     setTeam(%vehicleId, YELLOW);
  103.     
  104.     //if no one is IT, make this person IT
  105.     if(getItNum() == false)
  106.     {
  107.         %playerNum = playerManager::vehicleIdToPlayerNum(%vehicleId);
  108.         
  109.         dataStore(0, strcat(%playerNum, "isIt"), "Yes" );
  110.         wall(strcat(getName(%playerNum), " is now IT!"));
  111.     }
  112.     
  113.        if(playerManager::vehicleIdToPlayerNum(%vehicleId) == getItNum())
  114.     {
  115.         setTeam(%vehicleId, RED);
  116.         setVehicleSpecialIdentity(%vehicleId, true, RED);
  117.     }
  118. }
  119.  
  120. //----------------------------------------------
  121.  
  122. function vehicle::onDestroyed(%destroyedId, %destroyerId)
  123. {
  124.     %destroyerNum = playerManager::vehicleIdToPlayerNum(%destroyerId);
  125.     %destroyedNum = playerManager::vehicleIdToPlayerNum(%destroyedId);      
  126.     
  127.     if($tagWon == 1)
  128.     {
  129.         return;
  130.     }
  131.         
  132.     if(itKilledSelf(%destroyedNum, %destroyerNum))
  133.     {
  134.         return;
  135.     }
  136.     
  137.     if(itKilledPlayer(%destroyedNum, %destroyerNum))
  138.     {
  139.         return;
  140.     }
  141.     
  142.     if(playerKilledIt(%destroyedNum, %destroyerNum))
  143.     {
  144.         
  145.         setTeam(%destroyerId, RED);
  146.         
  147.         setVehicleSpecialIdentity(%destroyedId, false);
  148.         setVehicleSpecialIdentity(%destroyerId, true, RED);
  149.         return;
  150.     }
  151.     
  152. //     if we got here, a not-it player must have killed another not-it player
  153. //     which is ignored
  154. }
  155.  
  156. //--------------------------------------------------------
  157. function itKilledSelf(%destroyedNum, %destroyerNum)
  158. {
  159.     // if there is only one player, keep that player IT
  160.     
  161.     if(playerManager::getPlayerCount() == 1)
  162.        {
  163.         return true;
  164.     }
  165.  
  166.  
  167.     if(%destroyerNum == getItNum() && %destroyedNum == getItNum())
  168.     {
  169.         %newItNum = getHighScorePlayerNum(%playerNum);
  170.         
  171.            if(%newItNum != "" && %newItNum != 0)
  172.         {
  173.               dataStore(0, strcat(%destroyedNum, "isIt"), "No" );
  174.               dataStore(0, strcat(%newItNum, "isIt"), "Yes" );
  175.               
  176.               wall(strcat(getName(%newItNum), " is now IT!"));
  177.  
  178.             %vehicleId = playerManager::playerNumToVehicleId(%newItNum);
  179.             
  180.             setTeam(%vehicleId, RED);
  181.             setVehicleSpecialIdentity(%vehicleId, true, RED);
  182.         
  183.             resetAmmoTrigger(%newItNum);
  184.             resetHealTrigger(%newItNum);
  185.            }
  186.  
  187.         return true;
  188.     }
  189.     return false;
  190. }
  191.  
  192. //---------------------------------------------------------
  193. function itKilledPlayer(%destroyedNum, %destroyerNum)
  194. {
  195.     
  196.     if(%destroyerNum == getItNum())
  197.     {
  198.         %snuffKey    = strcat(%destroyerNum, "snuff");
  199.         %chokeKey     = strcat(%destroyedNum, "choke");
  200.         
  201.         dataStore(0, %snuffKey, 1 + dataRetrieve(0, %snuffKey));
  202.         dataStore(0, %chokeKey, 1 + dataRetrieve(0, %chokeKey));
  203.  
  204.         if(playerWonGame(%destroyerNum))
  205.         {
  206.             return true;
  207.         }
  208.         
  209.         else
  210.         {
  211.             wallDim(strcat(getName(%destroyedNum), " was Snuffed by IT!"));
  212.             %object = playerManager::playerNumToVehicleId(%destroyedNum);
  213.             chat(%object, 0, strcat(getName(%destroyedNum), " you CHOKED!"));
  214.         }
  215.         return true;
  216.     }
  217.     return false;
  218. }
  219.  
  220. //-------------------------------------------------------
  221. function playerKilledIt(%destroyedNum, %destroyerNum)
  222. {
  223.     
  224.     if(%destroyedNum == getItNum())
  225.     {    
  226.         %newItKey = strcat(%destroyerNum, "isIt");
  227.         %oldItKey = strcat(%destroyedNum, "isIt");
  228.         %sackKey  = strcat(%destroyerNum, "sack");
  229.  
  230.         dataStore(0, %oldItKey, "No");
  231.         dataStore(0, %newItkey, "Yes");
  232.         dataStore(0, %sackKey, 1 + dataRetrieve(0, %sackKey));
  233.         
  234.         if(playerWonGame(%destroyerNum))
  235.         {
  236.             return true;
  237.         }
  238.         
  239.         else
  240.         {    
  241.             wallDim(strcat(getName(%destroyerNum), " Sacked IT!"));
  242.               wall(strcat(getName(%destroyerNum), " is now IT!"));
  243.         }
  244.         
  245.         resetAmmoTrigger(%destroyerNum);
  246.         resetHealTrigger(%destroyerNum);
  247.  
  248.         
  249.         return true;
  250.     }
  251.     return false;
  252. }
  253.  
  254. //--------------------------------------------------------
  255. function getItNum()
  256. {
  257.     %count = playerManager::getPlayerCount();
  258.     for(%i = 0; %i < %count; %i = %i + 1)
  259.     {
  260.         %curPlayerNum = playerManager::getPlayerNum(%i);
  261.         if(dataRetrieve(0, strcat(%curPlayerNum, "isIt")) == "Yes")
  262.         {
  263.             return %curPlayerNum;
  264.         }    
  265.     }
  266.     //return false if no one is IT
  267.     return false;
  268. }
  269.  
  270. //--------------------------------------------------------
  271. function getHighScorePlayerNum(%playerNum)
  272. {
  273.     %highScore = 0;
  274.     %count = playerManager::getPlayerCount();
  275.     %highScorePlayerNum = "";
  276.     
  277.     for(%i = 0; %i < %count; %i = %i + 1)
  278.     {
  279.         %curPlayerNum = playerManager::getPlayerNum(%i);
  280.         %score = getPlayerScore(%curPlayerNum);
  281.         if(%curPlayerNum != %playerNum && %score >= %highScore)
  282.         {
  283.             %highScore = %score;
  284.             %highScorePlayerNum = %curPlayerNum;
  285.         }
  286.     }
  287.     
  288.     return %highScorePlayerNum;    
  289. }
  290.  
  291. //--------------------------------------------------------
  292. function initStats(%playerNum)
  293. {
  294.     dataStore(0, strcat(%playerNum, "snuff"), 0 );
  295.     dataStore(0, strcat(%playerNum, "choke"),0);
  296.     dataStore(0, strcat(%playerNum, "sack"),0);
  297.     dataStore(0, strcat(%playerNum, "isIt"),"No");
  298. }
  299.  
  300. //-------------------------------------------------------
  301. function playerWonGame(%playerNum)
  302. {
  303.     if(getPlayerScore(%playerNum) >= $winScore)
  304.     {
  305.         $tagWon = 1;
  306.         
  307.         wall("GAME OVER");
  308.         wall(strcat(getName(%playerNum), " won the Game!")); 
  309.         
  310.         %missionEnd = strcat(getName(%playerNum), " won the Game!");
  311.         messageBox(0, %missionEnd);
  312.  
  313.         %orderFade = "fadeEvent(0, out, 5, 0,0,0 );";
  314.         schedule(%orderFade, 5.0);
  315.         
  316.         schedule("missionEndConditionMet();", 10.0);
  317.  
  318.         return true;
  319.     }
  320.     return false;
  321.  
  322. //--------------------------------------------------------
  323. function cleanUp(%playerNum)
  324. {
  325.     dataRelease(0, strcat(%playerNum, "snuff"));
  326.     dataRelease(0, strcat(%playerNum, "choke"));
  327.     dataRelease(0, strcat(%playerNum, "sack"));
  328.     dataRelease(0, strcat(%playerNum, "isIt"));
  329. }
  330.  
  331. //--------------------------------------------------------
  332. //--Score board stuff
  333.  
  334. function getPlayerScore(%a)
  335. {
  336.     return (getPlayerSnuffs(%a) * $snuffValue + getPlayerSacks(%a) * $sackValue - getPlayerChokes(%a) * $chokeValue); // - getPlayerFriendlyKills(%a) * $friendlyKillValue);
  337. }
  338.  
  339. function getPlayerSnuffs(%playerNum)
  340. {
  341.     return dataRetrieve(0, strcat(%playerNum, "snuff"));
  342. }
  343.  
  344. function getPlayerSacks(%playerNum)
  345. {
  346.     return dataRetrieve(0, strcat(%playerNum, "sack"));    
  347. }
  348.  
  349. function getPlayerItStatus(%playerNum)
  350. {
  351.     return dataRetrieve(0, strcat(%playerNum, "isIt"));
  352.  
  353. }
  354.  
  355. function getPlayerChokes(%playerNum)
  356. {
  357.     return dataRetrieve(0, strcat(%playerNum, "choke"));
  358. }
  359.  
  360. //----------------------------------------------
  361. function initScoreboard()
  362. {
  363.    deleteVariables("$ScoreBoard::PlayerColumn*");
  364.    deleteVariables("$ScoreBoard::TeamColumn*");
  365.  
  366.    // Player ScoreBoard column headings
  367.    $ScoreBoard::PlayerColumnHeader1 = "SCORE";
  368.    $ScoreBoard::PlayerColumnHeader2 = "IT";
  369.    $ScoreBoard::PlayerColumnHeader3 = "SNUFFS";
  370.    $ScoreBoard::PlayerColumnHeader4 = "SACKS";
  371.    $ScoreBoard::PlayerColumnHeader5 = "CHOKES";
  372.    $ScoreBoard::PlayerColumnHeader5 = "PING";
  373.    
  374.    //Player ScoreBoard column functions
  375.    $ScoreBoard::PlayerColumnFunction1 = "getPlayerScore";
  376.    $ScoreBoard::PlayerColumnFunction2 = "getPlayerItStatus";
  377.    $ScoreBoard::PlayerColumnFunction3 = "getPlayerSnuffs";
  378.    $ScoreBoard::PlayerColumnFunction4 = "getPlayerSacks";
  379.    $ScoreBoard::PlayerColumnFunction5 = "getPlayerChokes";
  380.    $ScoreBoard::PlayerColumnFunction5 = "getPing";
  381.  
  382.    // tell server to process all the scoreboard definitions defined above
  383.    serverInitScoreBoard();
  384.     
  385. }
  386. // ------TRIGGER OVERLOADS-------------
  387. //--------------------------------------
  388. function heal::trigger::onEnter(%this, %object)
  389. {
  390.     %playerNum = playerManager::vehicleIdToPlayerNum(%object);
  391.     
  392.     //playSound(%object, IDCV_POWER_ON);
  393.     chat(%object, 0, "Entering repair area.");
  394.     
  395.     if(%playerNum == getItNum() && $healTriggerReady == true)
  396.     {    
  397.         healObject(%object, 10000.0);
  398.         healObject(%object, 10000.0);
  399.         healObject(%object, 10000.0);
  400.         $healTriggerReady = false;
  401.         
  402.         initResetHealTimer(%playerNum);
  403.         
  404.     }
  405. }
  406.  
  407.  
  408. //--------------------------------------
  409. function reload::trigger::onEnter(%this, %object)
  410. {
  411.     %playerNum = playerManager::vehicleIdToPlayerNum(%object);
  412.     
  413.     //playSound(%object, IDCV_POWER_ON);
  414.     chat(%object, 0, "Entering reload area.");
  415.     
  416.     if(%playerNum == getItNum() && $ammoTriggerReady == true)
  417.     {    
  418.         reloadObject(%object, 100.0);
  419.         $ammoTriggerReady = false;
  420.         
  421.         initResetAmmoTimer(%playerNum);
  422.  
  423.     }
  424. }
  425.  
  426.  
  427. //---------------------------------------------
  428. function initResetHealTimer(%playerNum)
  429. {
  430.     %playerCount = playerManager::getPlayerCount();
  431.     %timer = 70 - ((%playerCount - 1) * 5);
  432.  
  433.     if( %timer < 30)
  434.     {    
  435.         %timer = 30;
  436.     }
  437.  
  438.     %order = strcat("resetHealTrigger(", %playerNum, ");");
  439.     schedule (%order, %timer);
  440. }
  441.  
  442. //-----------------------------------------------
  443. function initResetAmmoTimer(%playerNum)
  444. {
  445.     %playerCount = playerManager::getPlayerCount();
  446.     %timer = 70 - ((%playerCount - 1) * 5);
  447.  
  448.     if( %timer < 30)
  449.     {    
  450.         %timer = 30;
  451.     }
  452.  
  453.     %order = strcat("resetAmmoTrigger(", %playerNum, ");");
  454.     schedule (%order, %timer);
  455. }
  456.     
  457. //---------------------------------------------
  458. function resetAmmoTrigger(%playerNum)
  459. {
  460.     %object = playerManager::playerNumToVehicleId(%playerNum);
  461.  
  462.     
  463.     if (%playerNum == getItNum())
  464.     {
  465.         $ammoTriggerReady = true;
  466.         chat(%object, 0, "RELOAD PAD IS READY!");
  467.     }
  468. }
  469.         
  470. //---------------------------------------------
  471. function resetHealTrigger(%playerNum)
  472. {
  473.     %object = playerManager::playerNumToVehicleId(%playerNum);
  474.  
  475.     if (%playerNum == getItNum())
  476.     {
  477.         $healTriggerReady = true;
  478.         chat(%object, 0, "HEAL PAD IS READY!");
  479.     }
  480. }
  481.  
  482. //--------------------------------------
  483.  
  484. function setKillValues()
  485. {    
  486.     %playerCount = playerManager::getPlayerCount();
  487.  
  488.     if(%playerCount <= 2)
  489.     {
  490.         $snuffValue = 2;
  491.         $sackValue     = 1;
  492.         $chokeValue = 0;
  493.         return;
  494.     }
  495.     
  496.        if(%playerCount == 3)
  497.     {
  498.         $snuffValue = 3;
  499.         $sackValue     = 1;
  500.         $chokeValue = 0;
  501.         return;
  502.     }
  503.     
  504.     if(%playerCount == 4)
  505.     {
  506.         $snuffValue = 4;
  507.         $sackValue     = 2;
  508.         $chokeValue = 1;
  509.         return;
  510.     }
  511.     
  512.     if(%playerCount == 5)
  513.     {
  514.         $snuffValue = 6;
  515.         $sackValue     = 3;
  516.         $chokeValue = 2;
  517.         return;
  518.     }
  519.     
  520.     if(%playerCount == 6)
  521.     {
  522.         $snuffValue = 8;
  523.         $sackValue     = 4;
  524.         $chokeValue = 2;
  525.         return;
  526.     }
  527.     
  528.     if(%playerCount >= 7)
  529.     {
  530.         $snuffValue = 10;
  531.         $sackValue     = 4;
  532.         $chokeValue = 2;
  533.         return;
  534.     }                    
  535.     
  536.     return;
  537. }
  538.  
  539. //------------------------------------------------------
  540.  
  541. function displayKillValues()
  542. {
  543.     wallDim(strcat("POINT UPDATE: SNUFF = ", $snuffValue, " | SACK = ", $sackValue, " | CHOKE = ", $chokeValue));    
  544. }
  545.  
  546. //---------------------------------------------------
  547. function boundryCheck()
  548. {
  549.     %itNum = getItNum();
  550.     %itName = getName(%itNum);
  551.     %itVehicle = playerManager::playerNumToVehicleId(%itNum);
  552.  
  553.     %distance = getDistance("MissionGroup/CenterPoint", %itVehicle);
  554.     
  555.     
  556.     if ( %distance >= 2000.0 )
  557.     {    
  558.         wallDim(strcat(%itName, " has run away!"));
  559.         wallDim(strcat("Say goodbye to your score ", %itName, "!"));
  560.         
  561.         // remove sacks and snuffs but keep chokes
  562.         
  563.         %snuffKey    = strcat(%itNum, "snuff");
  564.         %itKey         = strcat(%itNum, "isIt");
  565.         %sackKey      = strcat(%itNum, "sack");
  566.  
  567.         dataStore(0, %snuffKey, 0);
  568.         dataStore(0, %itKey, "No");
  569.         dataStore(0, %sackKey, 0);
  570.  
  571.         // select new It
  572.  
  573.         %newItNum = getHighScorePlayerNum(%playerNum);
  574.  
  575.            if(%newItNum != "" && %newItNum != 0)
  576.         {
  577.               dataStore(0, strcat(%newItNum, "isIt"), "Yes" );
  578.               wall(strcat(getName(%newItNum), " is now IT!"));
  579.            }
  580.     }
  581.  
  582.     %order = "boundryCheck();";
  583.     schedule(%order, 10.0);
  584.  
  585. }    
  586.  
  587.